<?php
	/**
	 *  tags 入口
	 *
	 */
	//PHPCMS根目录
	define('PHPCMS_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
	include PHPCMS_PATH.'/phpcms/base.php';
	pc_base::load_sys_func('global');
	$param = pc_base::load_sys_class('param');
	$keyword_db = pc_base::load_model('keyword_model');
	$keyword_data_db = pc_base::load_model('keyword_data_model');
	$siteid = get_siteid();
	$CATEGORYS = getcache('category_content_'.$siteid,'commons');

	//$tag = safe_replace(addslashes($_GET['tag']));
	$tag = urldecode(safe_replace(addslashes($_SERVER["QUERY_STRING"])));
	$tag = str_replace("/","",$tag);
	if(strpos($tag, "&") !== false){
		$tags = explode("&",$tag);
		$tag = str_replace("=","",$tags[0]);
	}
	if(empty($tag)){
		$page = max($_GET['page'], 1);
		$pagesize = 20;
		$where = '`siteid`='.$siteid;
		$infos = $keyword_db->listinfo($where, '`searchnums` DESC, `videonum` DESC', $page, $pagesize);
		$pages = $keyword_db->pages;
		$SEO = seo($siteid, '', "TAG标签");
		include template('content','tag');
	}else{
		//获取标签id
		$r = $keyword_db->get_one(array('keyword'=>$tag, 'siteid'=>$siteid), 'id');
		if (!$r['id']) showmessage('不存在此关键字！');
		$tagid = intval($r['id']);

		$page = max($_GET['page'], 1);
		$pagesize = 20;
		$where = '`tagid`=\''.$tagid.'\' AND `siteid`='.$siteid;
		$infos = $keyword_data_db->listinfo($where, '`id` DESC', $page, $pagesize);
		$pages = $keyword_data_db->pages;
		$total = $keyword_data_db->number;
		if (is_array($infos)) {
			$db = pc_base::load_model('content_model');
			$datas = array();
			foreach ($infos as $info) {
				list($contentid, $modelid) = explode('-', $info['contentid']);
				$db->set_model($modelid);
				$res = $db->get_one(array('id'=>$contentid), 'title, description, url, inputtime, style,catid,thumb,username');
				$res['title'] = str_replace($tag, '<font color="#f00">'.$tag.'</font>', $res['title']);
				$res['description'] = str_replace($tag, '<font color="#f00">'.$tag.'</font>', $res['description']);
				$datas[] = $res;
			}
		}
		$SEO = seo($siteid, '', $tag);
		include template('content','tag_list');
	}
?>